import os
from typing import Type
from .base_parser import BaseDocumentParser
from .pdf_parser import PDFParser
from .word_parser import WordParser

class DocumentParserFactory:
    """文档解析器工厂"""
    
    _parsers = {
        '.pdf': PDFParser,
        '.docx': WordParser,
        '.doc': WordParser
    }
    
    @classmethod
    def get_parser(cls, file_path: str, config: dict) -> BaseDocumentParser:
        """获取对应的解析器实例"""
        ext = os.path.splitext(file_path)[1].lower()
        
        if ext not in cls._parsers:
            raise ValueError(f"Unsupported file format: {ext}")
            
        parser_class = cls._parsers[ext]
        return parser_class(config) 